import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'


const routes: Array<RouteRecordRaw> = [
  {
    // 首页
    path: '/home',
    name: 'Home',
    component: () => import('@/views/home/index.vue')
  },
  {
    // 模块一
    path: '/module_one',
    component: () => import('@/views/module_one/index.vue'),
    children: [
      {
        path: '/module_one/module1',
        component: () => import('@/views/module_one/module1/index.vue')
      },
      {
        path: '/module_one/module2',
        component: () => import('@/views/module_one/module2.vue')
      },
      {
        path: '',
        redirect: {
          path:'/module_one/module1'
        }
      }
    ]
  },
  // 模块二
  {
    path: '/module_two/module1',
    component: () => import('@/views/module_two/module1.vue')
  },
  {
    path: '/module_two/module2',
    component: () => import('@/views/module_two/module2.vue')
  },
  {
    path: '/module_two/module3',
    component: () => import('@/views/module_two/module3.vue')
  },
  {
    path: '/',
    redirect: {
      name: 'Home',
    }
  }

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  // 每次路由跳转之后 新页面加载在x轴和y轴的初始位置
  scrollBehavior() {
    return {
      left: 0,
      top: 0,
    };
  },
})

export default router
